package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Notice;
import cn.wolfcode.trip.base.service.INoticeService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/notices")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;

    //添加一条关注记录
    @RequestMapping(method= RequestMethod.POST)
    public JsonResult save(Long noticeId, Long noticedId){
        JsonResult result = new JsonResult();
        try {
            noticeService.save(noticeId,noticedId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    //删除一条关注记录
    @RequestMapping(method= RequestMethod.DELETE)
    public JsonResult delete(Long noticeId, Long noticedId){
      JsonResult result = new JsonResult();
        try {
            noticeService.delete(noticeId, noticedId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    //查询
    @RequestMapping(method= RequestMethod.GET)
    public JsonResult selectOne(Long noticeId, Long noticedId){
      JsonResult result = new JsonResult();
        try {
          Notice notice = noticeService.selectOne(noticeId, noticedId);
          result.setResult(notice);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }

        return result;
    }

}
